<?php
	class Pengangkatan_pangkat_model extends Model{
		function Pengangkatan_pangkat_model(){
			parent::Model();
		}
        
        function list_pengangkatan_pangkat($where="", $order="", $ro=false) {
            if ($where!='') {
                $this->db->where($where);
            }
            if ($order == "") {
                $this->db->order_by('pangkat asc');
            } else {
                $this->db->order_by($order);
            }
            $q = $this->db->get('pengangkatan_pangkat');

            $s = "
              <table id=\"scrollable\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"tbl\">
                <thead>
                  <tr>
                    <th >No </th>
                    
                      <th> Pegawai </th>
                      <th>Pangkat</th>
                      <th >No Urut</th>
                      <th>TMT</th>
                      <th>Golongan</th>
                      <th>No. SK </th>
                      <th>Tgl. SK </th>
                      <th>Pejabat</th>
                    ";
            if ($ro==false) {
                $s .= " <th colspan='2'> Aksi </th>";
            }
            $s .= "</tr></thead><tbody>";
			$i = 1;

            $this->load->model('Datum_model');
            foreach($q->result() as $row) {
                if ($i % 2 == 1) {
                    $kelas = "event2";
                } else {
                    $kelas = "event";
                }

                $pegawai = Datum_model::getData('idspg_pegawai', 'pegawai', array('idspg_pegawai' => $row->id_pegawai));
                $golongan = Datum_model::getData('idspg_golongan', 'golongan', array('idspg_golongan' => $row->id_golongan)); 
                $pejabat = Datum_model::getData('idspg_pejabat', 'pejabat', array('idspg_pejabat' => $row->id_pejabat)); 
                
                $s .= "
              <tr class=\"$kelas\" id=\"row-".$row->idspg_pengangkatan_pangkat."\" >
                <td><div align=\"right\">$i.&nbsp;&nbsp;&nbsp;</div></td>
                <td>$pegawai</td>
                <td>".$row->pangkat."</td>
                <td>".$row->no_urut."</td>
                <td>".$row->tmt."</td>
                <td>$golongan</td>
                <td>".$row->no_sk."</td>
                <td>".$row->tgl_sk."</td>
                <td>$pejabat</td>
                ";
                if ($ro==false) {
                    $s .= "
                    <td><div align='center'> <a href='".base_url()."index.php/pengangkatan_pangkat/form_edit/".$row->idspg_pengangkatan_pangkat."' title=\"Ubah Data\" class=\"edit\"><img src='".base_url()."images/edit.gif' border='0'></a></div></td>";
                    if($this->input->post('page'))   
                    $s .= "<td><div align='center'><a href=\"javascript:deleteRow(".$row->idspg_pengangkatan_pangkat.")\"><img src='".base_url()."images/del.gif' border='0'></a></div></td>";
                }
                $s .= "
              </tr>";

                $i++;
            }
            $s .= "</tbody></table>";
            return $s;
        }

        function entry_pengangkatan_pangkat($form_id, $form_action, $arr=array()) {
        	
        	
        	$ret = "
			<form action='$form_action' method='post' name='pengangkatan_pangkat' id='$form_id'>

                <fieldset >
                 <table class='formTabel' border='0' align='center' cellpadding='5' cellspacing='1'>
           <!--       <tr>
                    <td class='kolom' valign='top'>Pegawai </td>
                    <td valign='top'>:</td>
                    <td valign='top'>
                      <input name='id_pegawai' type='text' id='id_pegawai' value='".(isset($arr['id_pegawai'])?$arr['id_pegawai']:"")."' size='5' maxlength='5' />
                       </td>
                  </tr>   -->
                 <tr>
                    <td class='kolom' valign='top'>No. Urut </td>
                    <td valign='top'>:</td>
                    <td valign='top'><input name='no_urut' type='text' id='no_urut' value='".(isset($arr['no_urut'])?$arr['no_urut']:"")."' size='5' maxlength='11' /></td>
                  </tr>
                  <tr>
                    <td class='kolom' valign='top'>Pangkat</td>
                    <td valign='top'>:</td>
                    <td valign='top'><input name='pangkat' type='text' id='pangkat' value='".(isset($arr['pangkat'])?$arr['pangkat']:"")."' size='50' maxlength='100' />
                       </td>
                  </tr>
                  <tr>
                    <td valign='top'>Golongan</td>
                    <td valign='top'>:</td>
                    <td valign='top'><select name='id_golongan' id='id_golongan'>
                        </select>
                       </td>
                  </tr>
                  <tr>
                    <td valign='top'>TMT </td>
                    <td valign='top'>:</td>
                    <td valign='top'><input name='tmt' type='text' id='tmt' value='".(isset($arr['tmt'])?$arr['tmt']:"")."' size='25'>
                       </td>
                  </tr>
                  <tr>
                    <td valign='top'>No. SK </td>
                    <td valign='top'>:</td>
                    <td valign='top'><input name='no_sk' type='text' id='no_sk' value='".(isset($arr['no_sk'])?$arr['no_sk']:"")."' size='45' maxlength='45' />
                       </td>
                  </tr>
                  <tr>
                    <td valign='top'>Tanggal SK </td>
                    <td valign='top'>:</td>
                    <td valign='top'><input name='tgl_sk' type='text' id='tgl_sk' value='".(isset($arr['tgl_sk'])?$arr['tgl_sk']:"")."' size='25'></td>
                  </tr>
                  <tr>
                    <td valign='top'>Pejabat</td>
                    <td valign='top'>:</td>
                    <td valign='top'><select name='id_pejabat' id='id_pejabat'>
                        </select></td>
                  </tr>
                  <tr>
                    <td valign='top'>&nbsp;</td>
                    <td valign='top'>&nbsp;</td>
                    <td valign='top'>
                      <input class=\"tombol\" type=\"button\" name=\"btn_kembali\" id=\"btn_kembali\" value=\"<< Kembali\" />
                  <input class=\"tombol\" type=\"submit\" name=\"button\" id=\"button\" value=\"   Simpan   \" />
                     </td>
                  </tr>
                </table>

                 <p>&nbsp;</p>
                </fieldset>

                </form>
			  ";
        	
        	return $ret;
        }

        function simpan($arr, $is_update=false, $id='') {
            if ($is_update==FALSE) {
                $this->db->insert('pengangkatan_pangkat', $arr);
            } else {
                $this->db->where('idspg_pengangkatan_pangkat', $id);
                $this->db->update('pengangkatan_pangkat', $arr);
            }
        }
        
	}
?>